

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="https://ikkiss.oss-cn-hangzhou.aliyuncs.com/images/myblog/IKKIS_LOGO.png">
  <link rel="icon" href="https://ikkiss.oss-cn-hangzhou.aliyuncs.com/images/myblog/IKKIS_LOGO.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Ikki">
  <meta name="keywords" content="">
  
    <meta name="description" content="formily是一款面向中后台复杂场景的数据+协议驱动的表单框架">
<meta property="og:type" content="article">
<meta property="og:title" content="formily基础">
<meta property="og:url" content="http://81.68.132.127/2022/11/11/formily/formily%E5%9F%BA%E7%A1%80/index.html">
<meta property="og:site_name" content="IKKI">
<meta property="og:description" content="formily是一款面向中后台复杂场景的数据+协议驱动的表单框架">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://ikkiss.oss-cn-hangzhou.aliyuncs.com/images/myblog/beijing/iTab-l35xgr.jpeg">
<meta property="article:published_time" content="2022-11-11T13:50:05.000Z">
<meta property="article:modified_time" content="2022-11-11T13:51:05.615Z">
<meta property="article:author" content="Ikki">
<meta property="article:tag" content="组件库">
<meta property="article:tag" content="formily">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://ikkiss.oss-cn-hangzhou.aliyuncs.com/images/myblog/beijing/iTab-l35xgr.jpeg">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>formily基础 - IKKI</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  



  
<link rel="stylesheet" href="/fluid/css/fluid-extention.css">
<link rel="stylesheet" href="/fluid/css/nihao.css">



  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"81.68.132.127","root":"/","version":"1.9.3","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"left","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":3},"lazyload":{"enable":true,"loading_img":"https://ikkiss.oss-cn-hangzhou.aliyuncs.com/images/myblog/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 5.4.2"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 100vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>Ikki-BUG制造者</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('http://image.ikki0603.cn') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="formily基础"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-11-11 21:50" pubdate>
          2022年11月11日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          24k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          200 分钟
        
      </span>
    

    
    
      
        <span id="busuanzi_container_page_pv" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="busuanzi_value_page_pv"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
        <div class="scroll-down-bar">
          <i class="iconfont icon-arrowdown"></i>
        </div>
      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="padding-left: 2rem; margin-right: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">formily基础</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：2022年11月11日 晚上
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <h2 id="2-formily"><a href="#2-formily" class="headerlink" title="2.formily "></a>2.formily </h2><ul>
<li>  <a target="_blank" rel="noopener" href="https://formilyjs.org/">formily</a>是一款面向中后台复杂场景的数据+协议驱动的表单框架，也是阿里巴巴集团统一表单解决方案,可以完成复杂表单需求，而且提供了表单设计器让我们快速设计表单</li>
</ul>
<h3 id="2-1-核心优势"><a href="#2-1-核心优势" class="headerlink" title="2.1 核心优势"></a>2.1 核心优势</h3><ul>
<li>  高性能 字段数据极多的情况下保持快速响应，可以实现高效联动逻辑</li>
<li>  跨端能力 与框架无关，可以兼容<code>react</code>和<code>vue</code>等框架</li>
<li>  生态完备 支持了业界主流的<code>antd</code>和<code>element</code>等组件库</li>
<li>  协议驱动 可以通过JSON驱动表单渲染，可以成为领域视图模型驱动的低代码渲染引擎</li>
</ul>
<h3 id="2-2-分层架构"><a href="#2-2-分层架构" class="headerlink" title="2.2 分层架构"></a>2.2 分层架构</h3><ul>
<li>  <a target="_blank" rel="noopener" href="https://core.formilyjs.org/zh-CN">@formily/core</a>负责管理表单的状态、校验和联动等</li>
<li>  <a target="_blank" rel="noopener" href="https://react.formilyjs.org/zh-CN/guide">@formily/react</a>是UI桥接库，用来接入内核数据实现最终的表单交互效果，不同框架有不同的桥接库</li>
<li>  <a target="_blank" rel="noopener" href="https://antd.formilyjs.org/zh-CN/components">@formily/antd</a>封装了场景化的组件</li>
</ul>
<p><img src="https://static.zhufengpeixun.com/cells_1655566023464.svg" srcset="https://ikkiss.oss-cn-hangzhou.aliyuncs.com/images/myblog/loading.gif" lazyload></p>
<ul>
<li>  这张图主要将 Formily 分为了内核协议层，UI胶水桥接层，扩展组件层，和配置应用层</li>
<li>  内核层是 UI 无关的，它保证了用户管理的逻辑和状态是不耦合任何一个框架</li>
<li>  JSON Schema 独立存在，给 UI 桥接层消费，保证了协议驱动在不同 UI 框架下的绝对一致性，不需要重复实现协议解析逻辑</li>
<li>  扩展组件层，提供一系列表单场景化组件，保证用户开箱即用。无需花大量时间做二次开发</li>
</ul>
<h3 id="2-3-竞品对比"><a href="#2-3-竞品对比" class="headerlink" title="2.3 竞品对比"></a>2.3 竞品对比</h3><p><img src="https://static.zhufengpeixun.com/formcompare_1655566386488.png" srcset="https://ikkiss.oss-cn-hangzhou.aliyuncs.com/images/myblog/loading.gif" lazyload></p>
<h3 id="2-4-安装"><a href="#2-4-安装" class="headerlink" title="2.4 安装"></a>2.4 安装</h3><figure class="highlight coffeescript"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-uca1wclacl5voy"></i><span>coffeescript</span><div class="collapse show" id="collapse-uca1wclacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs coffeescript"><span class="hljs-built_in">npm</span> init vite@latest<br><span class="hljs-built_in">npm</span> install @formily/reactive @formily/core @formily/reactive-react @formily/react @formily/antd ajv less --save<br><br></code></pre></td></tr></table></div></figure>

<h3 id="2-5-配置"><a href="#2-5-配置" class="headerlink" title="2.5 配置"></a>2.5 配置</h3><ul>
<li>  <a target="_blank" rel="noopener" href="https://github.com/vitejs/vite/tree/main/packages/plugin-react#opting-out-of-the-automatic-jsx-runtime">jsxRuntime</a></li>
<li>  在 <code>less`</code> 文件中引入 <code>antd</code> 的 <code>less</code> 文件会有一个<code>~</code>前置符，这种写法对于 ESM 构建工具是不兼容的</li>
<li>  <code>javascriptEnabled</code>这个参数在less3.0之后是默认为false</li>
</ul>
<p>vite.config.ts</p>
<figure class="highlight php"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-414ih1lacl5voy"></i><span>php</span><div class="collapse show" id="collapse-414ih1lacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><code class="hljs php">import &#123; defineConfig &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;vite&#x27;</span><br>import react <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@vitejs/plugin-react&#x27;</span><br><br><span class="hljs-comment">// https://vitejs.dev/config/</span><br>export <span class="hljs-keyword">default</span> <span class="hljs-title function_ invoke__">defineConfig</span>(&#123;<br>+ <span class="hljs-attr">plugins</span>: [<span class="hljs-title function_ invoke__">react</span>(&#123;<br>+   <span class="hljs-attr">jsxRuntime</span>: <span class="hljs-string">&#x27;classic&#x27;</span><br>+ &#125;)],<br>+ <span class="hljs-attr">resolve</span>: &#123;<br>+   <span class="hljs-attr">alias</span>: [<br>+     &#123; <span class="hljs-attr">find</span>: /^~/, <span class="hljs-attr">replacement</span>: <span class="hljs-string">&#x27;&#x27;</span> &#125;<br>+   ]<br>+ &#125;,<br>+ <span class="hljs-attr">css</span>: &#123;<br>+   <span class="hljs-attr">preprocessorOptions</span>: &#123;<br>+     <span class="hljs-attr">less</span>: &#123;<br>+       // 支持内联 JavaScript<br>+       <span class="hljs-attr">javascriptEnabled</span>: <span class="hljs-literal">true</span>,<br>+     &#125;<br>+   &#125;<br>+ &#125;<br>&#125;)<br><br></code></pre></td></tr></table></div></figure>

<p>tsconfig.json</p>
<figure class="highlight actionscript"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-t9g8vplacl5voy"></i><span>actionscript</span><div class="collapse show" id="collapse-t9g8vplacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><code class="hljs actionscript">&#123;<br>  <span class="hljs-string">&quot;compilerOptions&quot;</span>: &#123;<br>    <span class="hljs-string">&quot;target&quot;</span>: <span class="hljs-string">&quot;ESNext&quot;</span>,<br>    <span class="hljs-string">&quot;useDefineForClassFields&quot;</span>: <span class="hljs-literal">true</span>,<br>    <span class="hljs-string">&quot;lib&quot;</span>: [<span class="hljs-string">&quot;DOM&quot;</span>, <span class="hljs-string">&quot;DOM.Iterable&quot;</span>, <span class="hljs-string">&quot;ESNext&quot;</span>],<br>    <span class="hljs-string">&quot;allowJs&quot;</span>: <span class="hljs-literal">false</span>,<br>    <span class="hljs-string">&quot;skipLibCheck&quot;</span>: <span class="hljs-literal">true</span>,<br>    <span class="hljs-string">&quot;esModuleInterop&quot;</span>: <span class="hljs-literal">false</span>,<br>    <span class="hljs-string">&quot;allowSyntheticDefaultImports&quot;</span>: <span class="hljs-literal">true</span>,<br>+   <span class="hljs-string">&quot;strict&quot;</span>: <span class="hljs-literal">false</span>,<br>+   <span class="hljs-string">&quot;noImplicitAny&quot;</span>: <span class="hljs-literal">false</span>,<br>    <span class="hljs-string">&quot;forceConsistentCasingInFileNames&quot;</span>: <span class="hljs-literal">true</span>,<br>    <span class="hljs-string">&quot;module&quot;</span>: <span class="hljs-string">&quot;ESNext&quot;</span>,<br>    <span class="hljs-string">&quot;moduleResolution&quot;</span>: <span class="hljs-string">&quot;Node&quot;</span>,<br>    <span class="hljs-string">&quot;resolveJsonModule&quot;</span>: <span class="hljs-literal">true</span>,<br>    <span class="hljs-string">&quot;isolatedModules&quot;</span>: <span class="hljs-literal">true</span>,<br>    <span class="hljs-string">&quot;noEmit&quot;</span>: <span class="hljs-literal">true</span>,<br>    <span class="hljs-string">&quot;jsx&quot;</span>: <span class="hljs-string">&quot;react-jsx&quot;</span><br>  &#125;,<br>  <span class="hljs-string">&quot;include&quot;</span>: [<span class="hljs-string">&quot;src&quot;</span>],<br>  <span class="hljs-string">&quot;references&quot;</span>: [&#123; <span class="hljs-string">&quot;path&quot;</span>: <span class="hljs-string">&quot;./tsconfig.node.json&quot;</span> &#125;]<br>&#125;<br><br></code></pre></td></tr></table></div></figure>

<h2 id="3-字段数量多"><a href="#3-字段数量多" class="headerlink" title="3. 字段数量多 "></a>3. 字段数量多 </h2><h3 id="3-1-问题"><a href="#3-1-问题" class="headerlink" title="3.1 问题"></a>3.1 问题</h3><ul>
<li>  字段数量多，如何让性能不随字段数量增加而变差？</li>
</ul>
<h3 id="3-2-解决方案"><a href="#3-2-解决方案" class="headerlink" title="3.2 解决方案"></a>3.2 解决方案</h3><ul>
<li>  依赖<a target="_blank" rel="noopener" href="https://reactive.formilyjs.org/zh-CN">@formily/reactive</a>响应式解决方案，构建响应式表单的领域模型实现精确渲染</li>
</ul>
<p><img src="https://static.zhufengpeixun.com/Reaction_1655437930177.png" srcset="https://ikkiss.oss-cn-hangzhou.aliyuncs.com/images/myblog/loading.gif" lazyload></p>
<h4 id="3-2-1-MVVM"><a href="#3-2-1-MVVM" class="headerlink" title="3.2.1 MVVM"></a>3.2.1 MVVM</h4><ul>
<li>  MVVM（Model–view–viewmodel）是一种 OOP 软件架构模式，它的核心是将我们的应用程序的逻辑与视图做分离，提升代码可维护性与应用健壮性</li>
<li>  View(视图层)负责维护 UI 结构与样式，同时负责与 ViewModel(视图模型)做数据绑定</li>
<li>  这里的数据绑定关系是双向的，也就是，ViewModel(视图模型)的数据发生变化，会触发 View(视图层)的更新，同时视图层的数据变化又会触发 ViewModel(视图模型)的变化,Model 则更偏实际业务数据处理模型</li>
<li>  ViewModel 和 Model 都是充血模型，两者都注入了不同领域的业务逻辑，比如 ViewModel 的业务逻辑更偏视图交互层的领域逻辑，而 Model 的业务逻辑则更偏业务数据的处理逻辑</li>
<li>  Formily 它提供了 <code>View</code> 和 <code>ViewModel</code> 两层能力，<code>View</code> 则是<code>@formily/react</code>，专门用来与<code>@formily/core</code> 做桥接通讯的，所以，<code>@formily/core</code> 的定位就是 <code>ViewModel</code> 层</li>
</ul>
<p><img src="https://static.zhufengpeixun.com/MVVM_1655440368376.svg" srcset="https://ikkiss.oss-cn-hangzhou.aliyuncs.com/images/myblog/loading.gif" lazyload></p>
<figure class="highlight xml"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-09ru1nlacl5voy"></i><span>xml</span><div class="collapse show" id="collapse-09ru1nlacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-keyword">html</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">&quot;en&quot;</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">&quot;UTF-8&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">&quot;X-UA-Compatible&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;IE=edge&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;viewport&quot;</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>MVVM<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;bookTitle&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;红楼梦&quot;</span>/&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="language-javascript"></span><br><span class="language-javascript">        <span class="hljs-keyword">class</span> <span class="hljs-title class_">Book</span>&#123;</span><br><span class="language-javascript">            <span class="hljs-title function_">constructor</span>(<span class="hljs-params">title</span>)&#123;</span><br><span class="language-javascript">                <span class="hljs-variable language_">this</span>.<span class="hljs-property">title</span>=title;</span><br><span class="language-javascript">            &#125;</span><br><span class="language-javascript">        &#125;</span><br><span class="language-javascript">        <span class="hljs-comment">//Model</span></span><br><span class="language-javascript">        <span class="hljs-keyword">let</span> book = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Book</span>(<span class="hljs-string">&#x27;红楼梦&#x27;</span>);</span><br><span class="language-javascript">        <span class="hljs-comment">//ViewModel</span></span><br><span class="language-javascript">        <span class="hljs-keyword">let</span> viewModel = &#123;<span class="hljs-attr">display</span>:<span class="hljs-string">&#x27;block&#x27;</span>&#125;;</span><br><span class="language-javascript">        <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">defineProperty</span>(viewModel,<span class="hljs-string">&#x27;title&#x27;</span>,&#123;</span><br><span class="language-javascript">                <span class="hljs-title function_">get</span>(<span class="hljs-params"></span>)&#123;</span><br><span class="language-javascript">                    <span class="hljs-keyword">return</span> book.<span class="hljs-property">title</span>;</span><br><span class="language-javascript">                &#125;,</span><br><span class="language-javascript">                <span class="hljs-title function_">set</span>(<span class="hljs-params">newTitle</span>)&#123;</span><br><span class="language-javascript">                    bookTitle.<span class="hljs-property">value</span> = book.<span class="hljs-property">title</span> = newTitle;</span><br><span class="language-javascript">                &#125;</span><br><span class="language-javascript">        &#125;);</span><br><span class="language-javascript">        <span class="hljs-title class_">Object</span>.<span class="hljs-title function_">defineProperty</span>(viewModel,<span class="hljs-string">&#x27;display&#x27;</span>,&#123;</span><br><span class="language-javascript">                <span class="hljs-title function_">get</span>(<span class="hljs-params"></span>)&#123;</span><br><span class="language-javascript">                    <span class="hljs-keyword">return</span> bookTitle.<span class="hljs-property">style</span>.<span class="hljs-property">display</span>;</span><br><span class="language-javascript">                &#125;,</span><br><span class="language-javascript">                <span class="hljs-title function_">set</span>(<span class="hljs-params">display</span>)&#123;</span><br><span class="language-javascript">                    bookTitle.<span class="hljs-property">style</span>.<span class="hljs-property">display</span> = display;</span><br><span class="language-javascript">                &#125;</span><br><span class="language-javascript">        &#125;);</span><br><span class="language-javascript">        <span class="hljs-comment">//View(视图层)负责维护 UI 结构与样式</span></span><br><span class="language-javascript">        <span class="hljs-comment">//同时负责与 ViewModel(视图模型)做数据绑定</span></span><br><span class="language-javascript">        <span class="hljs-comment">//这里的数据绑定关系是双向的，也就是，ViewModel(视图模型)的数据发生变化，会触发 View(视图层)的更新</span></span><br><span class="language-javascript">        viewModel.<span class="hljs-property">title</span>=<span class="hljs-string">&#x27;新红楼梦&#x27;</span>;</span><br><span class="language-javascript">        <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">()=&gt;</span>&#123;</span><br><span class="language-javascript">            viewModel.<span class="hljs-property">display</span>= <span class="hljs-string">&#x27;none&#x27;</span>;</span><br><span class="language-javascript">        &#125;,<span class="hljs-number">3000</span>);</span><br><span class="language-javascript">        <span class="hljs-comment">//同时视图层的数据变化又会触发 ViewModel(视图模型)的变化</span></span><br><span class="language-javascript">        bookTitle.<span class="hljs-property">onchange</span> = <span class="hljs-function">(<span class="hljs-params">event</span>)=&gt;</span>&#123;</span><br><span class="language-javascript">            viewModel.<span class="hljs-property">title</span> = event.<span class="hljs-property">target</span>.<span class="hljs-property">value</span>;</span><br><span class="language-javascript">        &#125;</span><br><span class="language-javascript">    </span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span><br><br></code></pre></td></tr></table></div></figure>

<h4 id="3-2-2-observable"><a href="#3-2-2-observable" class="headerlink" title="3.2.2 observable"></a>3.2.2 observable</h4><ul>
<li>  <a target="_blank" rel="noopener" href="https://reactive.formilyjs.org/zh-CN/api/observable">observable</a>主要用于创建不同响应式行为的 <code>observable</code> 对象</li>
<li>  一个<code>observable</code>对象，字面意思是可订阅对象，我们通过创建一个可订阅对象，在每次操作该对象的属性数据的过程中，会自动通知订阅者</li>
<li>  <a target="_blank" rel="noopener" href="https://reactive.formilyjs.org/zh-CN">@formily/reactive</a> 创建 <a target="_blank" rel="noopener" href="https://reactive.formilyjs.org/zh-CN/api/observable">observable</a> 对象主要是通过 <code>ES Proxy</code> 来创建的，它可以做到完美劫持数据操作</li>
</ul>
<h4 id="3-2-2-Reaction"><a href="#3-2-2-Reaction" class="headerlink" title="3.2.2 Reaction"></a>3.2.2 Reaction</h4><ul>
<li>  `<a target="_blank" rel="noopener" href="https://reactive.formilyjs.org/zh-CN/api/reaction">reaction</a>在响应式编程模型中，它就相当于是可订阅对象的订阅者</li>
<li>  它接收一个 <code>tracker</code> 函数，这个函数在执行的时候，如果函数内部有对 <code>observable</code> 对象中的某个属性进行读操作会进行依赖收集，那当前 <code>reaction</code> 就会与该属性进行一个绑定(依赖追踪)，该属性在其它地方发生了写操作，就会触发 <code>tracker</code> 函数重复执行</li>
<li>  从订阅到派发订阅，其实是一个封闭的循环状态机，每次 <code>tracker</code> 函数执行的时候都会重新收集依赖，依赖变化时又会重新触发<code>tracker</code>执行</li>
</ul>
<h4 id="3-2-3-autorun"><a href="#3-2-3-autorun" class="headerlink" title="3.2.3 autorun"></a>3.2.3 autorun</h4><ul>
<li>  <a target="_blank" rel="noopener" href="https://reactive.formilyjs.org/zh-CN/api/autorun">autorun</a>可以创建一个自动执行的响应器</li>
<li>  接收一个 <code>tracker</code> 函数，如果函数内部有消费 <code>observable</code> 数据，数据发生变化时，<code>tracker</code> 函数会重复执行</li>
</ul>
<h4 id="3-2-4-实现observable"><a href="#3-2-4-实现observable" class="headerlink" title="3.2.4 实现observable"></a>3.2.4 实现observable</h4><h5 id="3-2-4-1-src-main-tsx"><a href="#3-2-4-1-src-main-tsx" class="headerlink" title="3.2.4.1 src\main.tsx"></a>3.2.4.1 src\main.tsx</h5><p>src\main.tsx</p>
<figure class="highlight pgsql"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-ejdakelacl5voy"></i><span>pgsql</span><div class="collapse show" id="collapse-ejdakelacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs pgsql"><span class="hljs-keyword">import</span> &#123; observable, autorun &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;./@formily/reactive&#x27;</span><br>const obs = observable(&#123;<br>  <span class="hljs-type">name</span>: <span class="hljs-string">&#x27;zhu&#x27;</span>,<br>&#125;)<br>const tracker = () =&gt; &#123;<br>  console.log(obs.name);<br>&#125;<br>autorun(tracker)<br>obs.name = <span class="hljs-string">&#x27;feng&#x27;</span>;<br><span class="hljs-comment">/**</span><br><span class="hljs-comment">zhu</span><br><span class="hljs-comment">feng</span><br><span class="hljs-comment"> */</span><br><br></code></pre></td></tr></table></div></figure>
<figure class="highlight javascript"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-7zyozylacl5voy"></i><span>javascript</span><div class="collapse show" id="collapse-7zyozylacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-keyword">import</span> &#123; observable, autorun &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@formily/reactive&#x27;</span><br><span class="hljs-keyword">const</span> obs = <span class="hljs-title function_">observable</span>(&#123;<br>  <span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;zhu&#x27;</span>,<br>+ <span class="hljs-attr">age</span>: <span class="hljs-number">12</span><br>&#125;)<br>+<span class="hljs-keyword">let</span> counter = <span class="hljs-number">0</span>;<br><span class="hljs-keyword">const</span> <span class="hljs-title function_">tracker</span> = (<span class="hljs-params"></span>) =&gt; &#123;<br>  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(obs.<span class="hljs-property">name</span>);<br>+ <span class="hljs-keyword">if</span> (counter++) &#123;<br>+   <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(obs.<span class="hljs-property">age</span>);<br>+ &#125;<br>&#125;<br><span class="hljs-title function_">autorun</span>(tracker)<br>+obs.<span class="hljs-property">age</span> = <span class="hljs-number">13</span>;<br>obs.<span class="hljs-property">name</span> = <span class="hljs-string">&#x27;feng&#x27;</span>;<br>+obs.<span class="hljs-property">age</span> = <span class="hljs-number">14</span>;<br><span class="hljs-comment">/**</span><br><span class="hljs-comment">tracker第1次执行</span><br><span class="hljs-comment">zhu</span><br><span class="hljs-comment">tracker第2次执行</span><br><span class="hljs-comment">feng</span><br><span class="hljs-comment">13</span><br><span class="hljs-comment">tracker第3次执行</span><br><span class="hljs-comment">feng</span><br><span class="hljs-comment">14</span><br><span class="hljs-comment"> */</span><br><br></code></pre></td></tr></table></div></figure>

<h5 id="3-2-4-2-reactive-index-ts"><a href="#3-2-4-2-reactive-index-ts" class="headerlink" title="3.2.4.2 reactive\index.ts"></a>3.2.4.2 reactive\index.ts</h5><p>src\@formily\reactive\index.ts</p>
<figure class="highlight javascript"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-ppthh7lacl5voy"></i><span>javascript</span><div class="collapse show" id="collapse-ppthh7lacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-keyword">const</span> <span class="hljs-title class_">RawReactionsMap</span> = <span class="hljs-keyword">new</span> <span class="hljs-title class_">WeakMap</span>()<br><span class="hljs-keyword">let</span> currentReaction;<br><span class="hljs-keyword">export</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">observable</span>(<span class="hljs-params">value</span>) &#123;<br>    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Proxy</span>(value, baseHandlers)<br>&#125;<br><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> <span class="hljs-title function_">autorun</span> = (<span class="hljs-params">tracker</span>) =&gt; &#123;<br>    <span class="hljs-keyword">const</span> <span class="hljs-title function_">reaction</span> = (<span class="hljs-params"></span>) =&gt; &#123;<br>        currentReaction = reaction;<br>        <span class="hljs-title function_">tracker</span>()<br>        currentReaction = <span class="hljs-literal">null</span>;<br>    &#125;<br>    <span class="hljs-title function_">reaction</span>()<br>&#125;<br><span class="hljs-keyword">const</span> baseHandlers = &#123;<br>    <span class="hljs-title function_">get</span>(<span class="hljs-params">target, key</span>) &#123;<br>        <span class="hljs-keyword">const</span> result = target[key]<br>        <span class="hljs-keyword">if</span> (currentReaction) &#123;<br>            <span class="hljs-title function_">addRawReactionsMap</span>(target, key, currentReaction)<br>        &#125;<br>        <span class="hljs-keyword">return</span> result<br>    &#125;,<br>    <span class="hljs-title function_">set</span>(<span class="hljs-params">target, key, value</span>) &#123;<br>        target[key] = value<br>        <span class="hljs-title class_">RawReactionsMap</span>.<span class="hljs-title function_">get</span>(target)?.<span class="hljs-title function_">get</span>(key)?.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">reaction</span>) =&gt;</span> <span class="hljs-title function_">reaction</span>())<br>        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;<br>    &#125;<br>&#125;<br><span class="hljs-keyword">const</span> <span class="hljs-title function_">addRawReactionsMap</span> = (<span class="hljs-params">target, key, reaction</span>) =&gt; &#123;<br>    <span class="hljs-keyword">const</span> reactionsMap = <span class="hljs-title class_">RawReactionsMap</span>.<span class="hljs-title function_">get</span>(target)<br>    <span class="hljs-keyword">if</span> (reactionsMap) &#123;<br>        <span class="hljs-keyword">const</span> reactions = reactionsMap.<span class="hljs-title function_">get</span>(key)<br>        <span class="hljs-keyword">if</span> (reactions) &#123;<br>            reactions.<span class="hljs-title function_">push</span>(reaction)<br>        &#125; <span class="hljs-keyword">else</span> &#123;<br>            reactionsMap.<span class="hljs-title function_">set</span>(key, [reaction])<br>        &#125;<br>        <span class="hljs-keyword">return</span> reactionsMap<br>    &#125; <span class="hljs-keyword">else</span> &#123;<br>        <span class="hljs-keyword">const</span> reactionsMap = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Map</span>()<br>        reactionsMap.<span class="hljs-title function_">set</span>(key, [reaction]);<br>        <span class="hljs-title class_">RawReactionsMap</span>.<span class="hljs-title function_">set</span>(target, reactionsMap)<br>        <span class="hljs-keyword">return</span> reactionsMap<br>    &#125;<br>&#125;<br><br></code></pre></td></tr></table></div></figure>

<h4 id="3-2-5-Observer"><a href="#3-2-5-Observer" class="headerlink" title="3.2.5 Observer"></a>3.2.5 Observer</h4><ul>
<li>  <a target="_blank" rel="noopener" href="https://reactive.formilyjs.org/zh-CN/api/react/observer">Observer</a>接收一个 <code>Function RenderProps</code>，只要在 <code>Function</code> 内部消费到的任何响应式数据，都会随数据变化而自动重新渲染，也更容易实现局部精确渲染</li>
</ul>
<h5 id="3-2-5-1-src-main-tsx"><a href="#3-2-5-1-src-main-tsx" class="headerlink" title="3.2.5.1 src\main.tsx"></a>3.2.5.1 src\main.tsx</h5><p>src\main.tsx</p>
<figure class="highlight javascript"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-8rejkmlacl5voy"></i><span>javascript</span><div class="collapse show" id="collapse-8rejkmlacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-keyword">import</span> <span class="hljs-title class_">React</span> <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;react&#x27;</span><br><span class="hljs-keyword">import</span> <span class="hljs-title class_">ReactDOM</span> <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;react-dom&#x27;</span><br><span class="hljs-keyword">import</span> <span class="hljs-title class_">App</span> <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;./App&#x27;</span>;<br><span class="hljs-title class_">ReactDOM</span>.<span class="hljs-title function_">render</span>(<span class="language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">App</span> /&gt;</span></span>, <span class="hljs-variable language_">document</span>.<span class="hljs-title function_">getElementById</span>(<span class="hljs-string">&#x27;root&#x27;</span>)!);<br><br></code></pre></td></tr></table></div></figure>

<h5 id="3-2-5-2-src-App-tsx"><a href="#3-2-5-2-src-App-tsx" class="headerlink" title="3.2.5.2 src\App.tsx"></a>3.2.5.2 src\App.tsx</h5><p>src\App.tsx</p>
<figure class="highlight javascript"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-zze1svlacl5voy"></i><span>javascript</span><div class="collapse show" id="collapse-zze1svlacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-keyword">import</span> &#123; observable &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;./@formily/reactive&#x27;</span><br><span class="hljs-keyword">import</span> &#123; <span class="hljs-title class_">Observer</span> &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;./@formily/reactive-react&#x27;</span><br><span class="hljs-keyword">const</span> username = <span class="hljs-title function_">observable</span>(&#123; <span class="hljs-attr">value</span>: <span class="hljs-string">&#x27;zhangsan&#x27;</span> &#125;)<br><span class="hljs-keyword">const</span> age = <span class="hljs-title function_">observable</span>(&#123; <span class="hljs-attr">value</span>: <span class="hljs-number">14</span> &#125;)<br><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> () =&gt; &#123;<br>  <span class="hljs-keyword">return</span> (<br>    <span class="language-xml"><span class="hljs-tag">&lt;&gt;</span></span><br><span class="language-xml">      <span class="hljs-tag">&lt;<span class="hljs-name">Observer</span>&gt;</span></span><br><span class="language-xml">        &#123;() =&gt; (</span><br><span class="language-xml">          <span class="hljs-tag">&lt;<span class="hljs-name">input</span></span></span><br><span class="hljs-tag"><span class="language-xml">            <span class="hljs-attr">value</span>=<span class="hljs-string">&#123;username.value&#125;</span></span></span><br><span class="hljs-tag"><span class="language-xml">            <span class="hljs-attr">onChange</span>=<span class="hljs-string">&#123;(event)</span> =&gt;</span> &#123;</span><br><span class="language-xml">              username.value = event.target.value</span><br><span class="language-xml">            &#125;&#125;</span><br><span class="language-xml">          /&gt;</span><br><span class="language-xml">        )&#125;</span><br><span class="language-xml">      <span class="hljs-tag">&lt;/<span class="hljs-name">Observer</span>&gt;</span></span><br><span class="language-xml">      <span class="hljs-tag">&lt;<span class="hljs-name">Observer</span>&gt;</span>&#123;() =&gt; &#123;</span><br><span class="language-xml">        console.log(&#x27;username render&#x27;);</span><br><span class="language-xml">        return <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>&#123;username.value&#125;<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>;</span><br><span class="language-xml">      &#125;&#125;<span class="hljs-tag">&lt;/<span class="hljs-name">Observer</span>&gt;</span></span><br><span class="language-xml">      <span class="hljs-tag">&lt;<span class="hljs-name">Observer</span>&gt;</span></span><br><span class="language-xml">        &#123;() =&gt; (</span><br><span class="language-xml">          <span class="hljs-tag">&lt;<span class="hljs-name">input</span></span></span><br><span class="hljs-tag"><span class="language-xml">            <span class="hljs-attr">value</span>=<span class="hljs-string">&#123;age.value&#125;</span></span></span><br><span class="hljs-tag"><span class="language-xml">            <span class="hljs-attr">onChange</span>=<span class="hljs-string">&#123;(event)</span> =&gt;</span> &#123;</span><br><span class="language-xml">              age.value = +event.target.value</span><br><span class="language-xml">            &#125;&#125;</span><br><span class="language-xml">          /&gt;</span><br><span class="language-xml">        )&#125;</span><br><span class="language-xml">      <span class="hljs-tag">&lt;/<span class="hljs-name">Observer</span>&gt;</span></span><br><span class="language-xml">      <span class="hljs-tag">&lt;<span class="hljs-name">Observer</span>&gt;</span>&#123;() =&gt; &#123;</span><br><span class="language-xml">        console.log(&#x27;age render&#x27;);</span><br><span class="language-xml">        return <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>&#123;age.value&#125;<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>;</span><br><span class="language-xml">      &#125;&#125;<span class="hljs-tag">&lt;/<span class="hljs-name">Observer</span>&gt;</span></span><br><span class="language-xml">    <span class="hljs-tag">&lt;/&gt;</span></span><br>  )<br>&#125;<br><br></code></pre></td></tr></table></div></figure>

<h5 id="3-2-5-3-reactive-react-index-tsx"><a href="#3-2-5-3-reactive-react-index-tsx" class="headerlink" title="3.2.5.3 reactive-react\index.tsx"></a>3.2.5.3 reactive-react\index.tsx</h5><p>src\@formily\reactive-react\index.tsx</p>
<figure class="highlight javascript"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-owvla1lacl5voy"></i><span>javascript</span><div class="collapse show" id="collapse-owvla1lacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-keyword">import</span> <span class="hljs-title class_">React</span>, &#123; useReducer &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;react&#x27;</span>;<br><span class="hljs-keyword">import</span> &#123; <span class="hljs-title class_">Tracker</span> &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;../../@formily/reactive&#x27;</span><br><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> <span class="hljs-title function_">Observer</span> = (<span class="hljs-params">props</span>) =&gt; &#123;<br>    <span class="hljs-keyword">const</span> [, forceUpdate] = <span class="hljs-title function_">useReducer</span>(<span class="hljs-function"><span class="hljs-params">x</span> =&gt;</span> x + <span class="hljs-number">1</span>, <span class="hljs-number">0</span>)<br>    <span class="hljs-keyword">const</span> trackerRef = <span class="hljs-title class_">React</span>.<span class="hljs-title function_">useRef</span>(<span class="hljs-literal">null</span>)<br>    <span class="hljs-keyword">if</span> (!trackerRef.<span class="hljs-property">current</span>)<br>        trackerRef.<span class="hljs-property">current</span> = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Tracker</span>(forceUpdate)<br>    <span class="hljs-keyword">return</span> trackerRef.<span class="hljs-property">current</span>.<span class="hljs-title function_">track</span>(props.<span class="hljs-property">children</span>)<br>&#125;<br><br></code></pre></td></tr></table></div></figure>

<h5 id="3-2-5-4-reactive-index-ts"><a href="#3-2-5-4-reactive-index-ts" class="headerlink" title="3.2.5.4 reactive\index.ts"></a>3.2.5.4 reactive\index.ts</h5><p>src\@formily\reactive\index.ts</p>
<figure class="highlight javascript"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-q5y023lacl5voy"></i><span>javascript</span><div class="collapse show" id="collapse-q5y023lacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-keyword">const</span> <span class="hljs-title class_">RawReactionsMap</span> = <span class="hljs-keyword">new</span> <span class="hljs-title class_">WeakMap</span>()<br><span class="hljs-keyword">let</span> currentReaction;<br><span class="hljs-keyword">export</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">observable</span>(<span class="hljs-params">value</span>) &#123;<br>    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Proxy</span>(value, baseHandlers)<br>&#125;<br><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> <span class="hljs-title function_">autorun</span> = (<span class="hljs-params">tracker</span>) =&gt; &#123;<br>    <span class="hljs-keyword">const</span> <span class="hljs-title function_">reaction</span> = (<span class="hljs-params"></span>) =&gt; &#123;<br>        currentReaction = reaction;<br>        <span class="hljs-title function_">tracker</span>()<br>        currentReaction = <span class="hljs-literal">null</span>;<br>    &#125;<br>    <span class="hljs-title function_">reaction</span>()<br>&#125;<br><span class="hljs-keyword">const</span> baseHandlers = &#123;<br>    <span class="hljs-title function_">get</span>(<span class="hljs-params">target, key</span>) &#123;<br>        <span class="hljs-keyword">const</span> result = target[key]<br>        <span class="hljs-keyword">if</span> (currentReaction) &#123;<br>            <span class="hljs-title function_">addRawReactionsMap</span>(target, key, currentReaction)<br>        &#125;<br>        <span class="hljs-keyword">return</span> result<br>    &#125;,<br>    <span class="hljs-title function_">set</span>(<span class="hljs-params">target, key, value</span>) &#123;<br>        target[key] = value<br>        <span class="hljs-title class_">RawReactionsMap</span>.<span class="hljs-title function_">get</span>(target)?.<span class="hljs-title function_">get</span>(key)?.<span class="hljs-title function_">forEach</span>(<span class="hljs-function">(<span class="hljs-params">reaction</span>) =&gt;</span> &#123;<br>+           <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> reaction.<span class="hljs-property">_scheduler</span> === <span class="hljs-string">&#x27;function&#x27;</span>) &#123;<br>+               reaction.<span class="hljs-title function_">_scheduler</span>()<br>+           &#125; <span class="hljs-keyword">else</span> &#123;<br>+               <span class="hljs-title function_">reaction</span>()<br>+           &#125;<br>        &#125;)<br>        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;<br>    &#125;<br>&#125;<br><span class="hljs-keyword">const</span> <span class="hljs-title function_">addRawReactionsMap</span> = (<span class="hljs-params">target, key, reaction</span>) =&gt; &#123;<br>    <span class="hljs-keyword">const</span> reactionsMap = <span class="hljs-title class_">RawReactionsMap</span>.<span class="hljs-title function_">get</span>(target)<br>    <span class="hljs-keyword">if</span> (reactionsMap) &#123;<br>        <span class="hljs-keyword">const</span> reactions = reactionsMap.<span class="hljs-title function_">get</span>(key)<br>        <span class="hljs-keyword">if</span> (reactions) &#123;<br>            reactions.<span class="hljs-title function_">push</span>(reaction)<br>        &#125; <span class="hljs-keyword">else</span> &#123;<br>            reactionsMap.<span class="hljs-title function_">set</span>(key, [reaction])<br>        &#125;<br>        <span class="hljs-keyword">return</span> reactionsMap<br>    &#125; <span class="hljs-keyword">else</span> &#123;<br>        <span class="hljs-keyword">const</span> reactionsMap = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Map</span>()<br>        reactionsMap.<span class="hljs-title function_">set</span>(key, [reaction]);<br>        <span class="hljs-title class_">RawReactionsMap</span>.<span class="hljs-title function_">set</span>(target, reactionsMap)<br>        <span class="hljs-keyword">return</span> reactionsMap<br>    &#125;<br>&#125;<br><br>+<span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Tracker</span> &#123;<br>+    <span class="hljs-title function_">constructor</span>(<span class="hljs-params">scheduler</span>) &#123;<br>+        <span class="hljs-variable language_">this</span>.<span class="hljs-property">track</span>.<span class="hljs-property">_scheduler</span> = scheduler<br>+    &#125;<br>+    <span class="hljs-attr">track</span>: any = <span class="hljs-function">(<span class="hljs-params">tracker</span>) =&gt;</span> &#123;<br>+        currentReaction = <span class="hljs-variable language_">this</span>.<span class="hljs-property">track</span>;<br>+        <span class="hljs-keyword">return</span> <span class="hljs-title function_">tracker</span>()<br>+    &#125;<br>+&#125;<br><br></code></pre></td></tr></table></div></figure>

<h2 id="4-字段关联逻辑复杂"><a href="#4-字段关联逻辑复杂" class="headerlink" title="4. 字段关联逻辑复杂 "></a>4. 字段关联逻辑复杂 </h2><h3 id="4-1-问题"><a href="#4-1-问题" class="headerlink" title="4.1 问题"></a>4.1 问题</h3><ul>
<li>字段关联逻辑复杂，如何更简单的实现复杂的联动逻辑？字段与字段关联时，如何保证不影响表单性能？<ul>
<li>  一对多(异步)</li>
<li>  多对一(异步)</li>
<li>  多对多(异步)</li>
</ul>
</li>
</ul>
<h3 id="4-2-领域模型"><a href="#4-2-领域模型" class="headerlink" title="4.2 领域模型"></a>4.2 领域模型</h3><ul>
<li>  字段值的改变和应用状态、服务器返回数据等都可能会引发字段的联动</li>
<li>  联动关系核心是将字段的某些状态属性与某些数据关联起来</li>
<li>  可以定义针对表单领域的<code>领域模型</code></li>
<li>  <a target="_blank" rel="noopener" href="https://core.formilyjs.org/zh-CN/api/models/form">Form</a>是调用<code>createForm</code>所返回的核心表单模型</li>
<li>  <a target="_blank" rel="noopener" href="https://core.formilyjs.org/zh-CN/api/models/field">Field</a>是调用<code>createField</code>所返回的字段模型</li>
<li>  <a target="_blank" rel="noopener" href="https://core.formilyjs.org/zh-CN/api/entry/create-form">createForm</a>用来创建表单核心领域模型，它是作为MVVM设计模式的标准 <code>ViewModel</code></li>
</ul>
<p><img src="https://static.zhufengpeixun.com/fields_1655444784309.svg" srcset="https://ikkiss.oss-cn-hangzhou.aliyuncs.com/images/myblog/loading.gif" lazyload></p>
<p>src\main.tsx</p>
<figure class="highlight javascript"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-wxt2wklacl5voy"></i><span>javascript</span><div class="collapse show" id="collapse-wxt2wklacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-keyword">import</span> &#123; createForm &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@formily/core&#x27;</span><br><span class="hljs-keyword">const</span> form = <span class="hljs-title function_">createForm</span>()<br><span class="hljs-keyword">const</span> field = form.<span class="hljs-title function_">createField</span>(&#123; <span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;target&#x27;</span> &#125;)<br><br></code></pre></td></tr></table></div></figure>

<h3 id="4-3-DDD-领域驱动"><a href="#4-3-DDD-领域驱动" class="headerlink" title="4.3 DDD(领域驱动)"></a>4.3 DDD(领域驱动)</h3><ul>
<li>  DDD(Domain-Driven Design)即领域驱动设计是思考问题的方法论,用于对实际问题建模</li>
<li>  它以一种领域专家、设计人员、开发人员都能理解的通用语言作为相互交流的工具，然后将这些概念设计成一个领域模型。由领域模型驱动软件设计，用代码来实现该领域模型</li>
</ul>
<h4 id="4-3-1-表单"><a href="#4-3-1-表单" class="headerlink" title="4.3.1 表单"></a>4.3.1 表单</h4><figure class="highlight awk"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-va010nlacl5voy"></i><span>awk</span><div class="collapse show" id="collapse-va010nlacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs awk">interface Form &#123;<br>   values,<span class="hljs-regexp">//</span>值<br>   visible, <span class="hljs-regexp">//</span>是否可见<br>   submit() <span class="hljs-regexp">//</span>提交<br>&#125;<br><br></code></pre></td></tr></table></div></figure>

<h4 id="4-3-2-字段"><a href="#4-3-2-字段" class="headerlink" title="4.3.2 字段"></a>4.3.2 字段</h4><figure class="highlight awk"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-qgi3lulacl5voy"></i><span>awk</span><div class="collapse show" id="collapse-qgi3lulacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs awk">interface Field &#123;<br>   value,     <span class="hljs-regexp">//</span>值<br>   visible,   <span class="hljs-regexp">//</span>是否可见<br>   setValue() <span class="hljs-regexp">//</span>设置值<br>&#125;<br><br></code></pre></td></tr></table></div></figure>

<h3 id="4-4-路径系统"><a href="#4-4-路径系统" class="headerlink" title="4.4 路径系统"></a>4.4 路径系统</h3><ul>
<li>  表单模型作为顶层模型管理着所有字段模型，每个字段都有着自己的路径</li>
<li>  如何优雅的查找某个字段?</li>
<li>  Formily 独创的路径系统<a target="_blank" rel="noopener" href="https://core.formilyjs.org/zh-CN/api/entry/form-path">@formily/path</a>让字段查找变得优雅</li>
<li>  <code>FormPath</code> 在 Formily 中核心是解决路径匹配问题和数据操作问题</li>
</ul>
<p>src\main.tsx</p>
<figure class="highlight reasonml"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-7y6u8alacl5voy"></i><span>reasonml</span><div class="collapse show" id="collapse-7y6u8alacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs reasonml">import &#123; FormPath &#125; from &#x27;@formily/core&#x27;<br>const target = &#123; <span class="hljs-built_in">array</span>: <span class="hljs-literal">[]</span> &#125;<br><span class="hljs-comment">//点路径 就是我们最常用的a.b.c格式，用点符号来分割每个路径节点，主要用来读写数据</span><br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">FormPath</span>.</span></span>set<span class="hljs-constructor">In(<span class="hljs-params">target</span>, &#x27;<span class="hljs-params">a</span>.<span class="hljs-params">b</span>.<span class="hljs-params">c</span>&#x27;, &#x27;<span class="hljs-params">dotValue</span>&#x27;)</span><br>console.log(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">FormPath</span>.</span></span>get<span class="hljs-constructor">In(<span class="hljs-params">target</span>, &#x27;<span class="hljs-params">a</span>.<span class="hljs-params">b</span>.<span class="hljs-params">c</span>&#x27;)</span>) <span class="hljs-comment">//&#x27;dotValue&#x27;</span><br><br><span class="hljs-comment">//下标路径 对于数组路径，都会有下标，我们的下标可以用点语法，也可以用中括号</span><br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">FormPath</span>.</span></span>set<span class="hljs-constructor">In(<span class="hljs-params">target</span>, &#x27;<span class="hljs-params">array</span>.0.<span class="hljs-params">d</span>&#x27;, &#x27;<span class="hljs-params">arrayValue</span>&#x27;)</span><br>console.log(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">FormPath</span>.</span></span>get<span class="hljs-constructor">In(<span class="hljs-params">target</span>, &#x27;<span class="hljs-params">array</span>.0.<span class="hljs-params">d</span>&#x27;)</span>) <span class="hljs-comment">//arrayValue</span><br><br><span class="hljs-comment">//解构表达式 解构表达式类似于 ES6 的解构语法,在前后端数据不一致的场景非常适用,解构表达式会作为点路径的某个节点</span><br><span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">FormPath</span>.</span></span>set<span class="hljs-constructor">In(<span class="hljs-params">target</span>, &#x27;<span class="hljs-params">parent</span>.[<span class="hljs-params">f</span>,<span class="hljs-params">g</span>]&#x27;, [1, 2])</span><br><br>console.log(<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">JSON</span>.</span></span>stringify(target))<br><span class="hljs-comment">//&#123;&quot;array&quot;:[&#123;&quot;d&quot;:&quot;arrayValue&quot;&#125;],&quot;a&quot;:&#123;&quot;b&quot;:&#123;&quot;c&quot;:&quot;dotValue&quot;&#125;&#125;,&quot;parent&quot;:&#123;&quot;f&quot;:1,&quot;g&quot;:2&#125;&#125;</span><br><br></code></pre></td></tr></table></div></figure>

<h2 id="5-生命周期"><a href="#5-生命周期" class="headerlink" title="5. 生命周期 "></a>5. 生命周期 </h2><h3 id="5-1-问题"><a href="#5-1-问题" class="headerlink" title="5.1 问题"></a>5.1 问题</h3><ul>
<li>  响应式和路径系统组成一个较为完备的表单方案,但是一个黑盒</li>
<li>  想要在某个过程阶段内实现一些自定义逻辑如何实现?</li>
</ul>
<h3 id="5-2-解决方案"><a href="#5-2-解决方案" class="headerlink" title="5.2 解决方案"></a>5.2 解决方案</h3><ul>
<li>  <a target="_blank" rel="noopener" href="https://core.formilyjs.org/zh-CN/api/entry/form-effect-hooks">Form Effect Hooks</a>可以将整个表单生命周期作为事件钩子暴露给外界，这样就能做到了既有抽象，但又灵活的表单方案</li>
<li>  <a target="_blank" rel="noopener" href="https://core.formilyjs.org/zh-CN/api/entry/form-effect-hooks#onforminit">onFormInit</a>用于监听某个表单初始化的副作用钩子，我们在调用 createForm 的时候就会触发初始化事件</li>
<li>  <a target="_blank" rel="noopener" href="https://core.formilyjs.org/zh-CN/api/entry/form-effect-hooks#%E6%8F%8F%E8%BF%B0-3">onFormReact</a>用于实现表单响应式逻辑的副作用钩子，它的核心原理就是表单初始化的时候会执行回调函数，同时自动追踪依赖，依赖数据发生变化时回调函数会重复执行</li>
</ul>
<figure class="highlight stylus"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-5l9fw1lacl5voy"></i><span>stylus</span><div class="collapse show" id="collapse-5l9fw1lacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><code class="hljs stylus">import &#123; useMemo, useState &#125; from <span class="hljs-string">&#x27;react&#x27;</span><br>import &#123; createForm, onFormInit, onFormReact &#125; from <span class="hljs-string">&#x27;@formily/core&#x27;</span><br>export default () =&gt; &#123;<br>  const <span class="hljs-selector-attr">[state, setState]</span> = <span class="hljs-built_in">useState</span>(<span class="hljs-string">&#x27;init&#x27;</span>)<br>  const <span class="hljs-selector-tag">form</span> = <span class="hljs-built_in">useMemo</span>(<br>    () =&gt;<br>      <span class="hljs-built_in">createForm</span>(&#123;<br>        <span class="hljs-built_in">effects</span>() &#123;<br>          <span class="hljs-built_in">onFormInit</span>(() =&gt; &#123;<br>            <span class="hljs-built_in">setState</span>(<span class="hljs-string">&#x27;表单已初始化&#x27;</span>)<br>          &#125;)<br>          <span class="hljs-built_in">onFormReact</span>((form) =&gt; &#123;<br>            <span class="hljs-keyword">if</span> (<span class="hljs-selector-tag">form</span><span class="hljs-selector-class">.values</span><span class="hljs-selector-class">.input</span> == <span class="hljs-string">&#x27;Hello&#x27;</span>) &#123;<br>              <span class="hljs-built_in">setState</span>(<span class="hljs-string">&#x27;响应Hello&#x27;</span>)<br>            &#125; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-selector-tag">form</span><span class="hljs-selector-class">.values</span><span class="hljs-selector-class">.input</span> == <span class="hljs-string">&#x27;World&#x27;</span>) &#123;<br>              <span class="hljs-built_in">setState</span>(<span class="hljs-string">&#x27;响应World&#x27;</span>)<br>            &#125;<br>          &#125;)<br>        &#125;,<br><br>      &#125;),<br>    <span class="hljs-selector-attr">[]</span><br>  )<br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;&#123;state&#125;&lt;/p&gt;<br>      &lt;<span class="hljs-selector-tag">button</span><br>        onClick=&#123;() =&gt; &#123;<br>          <span class="hljs-selector-tag">form</span><span class="hljs-selector-class">.setValuesIn</span>(<span class="hljs-string">&#x27;input&#x27;</span>, <span class="hljs-string">&#x27;Hello&#x27;</span>)<br>        &#125;&#125;<br>      &gt;<br>        Hello<br>      &lt;/button&gt;<br>      &lt;<span class="hljs-selector-tag">button</span><br>        onClick=&#123;() =&gt; &#123;<br>          <span class="hljs-selector-tag">form</span><span class="hljs-selector-class">.setValuesIn</span>(<span class="hljs-string">&#x27;input&#x27;</span>, <span class="hljs-string">&#x27;World&#x27;</span>)<br>        &#125;&#125;<br>      &gt;<br>        World<br>      &lt;/button&gt;<br>    &lt;/div&gt;<br>  )<br>&#125;<br><br></code></pre></td></tr></table></div></figure>

<h2 id="6-协议驱动"><a href="#6-协议驱动" class="headerlink" title="6 协议驱动 "></a>6 协议驱动 </h2><h3 id="6-1-问题"><a href="#6-1-问题" class="headerlink" title="6.1 问题"></a>6.1 问题</h3><ul>
<li>动态渲染述求很强烈<ul>
<li>  字段配置化，让非专业前端也能快速搭建复杂表单</li>
<li>  跨端渲染，一份 JSON Schema，多端适配</li>
<li>如何在表单协议中描述布局？<ul>
<li>  纵向布局</li>
<li>  横向布局</li>
<li>  网格布局</li>
<li>  弹性布局</li>
<li>  自由布局</li>
</ul>
</li>
<li>  如何在表单协议中描述逻辑？</li>
</ul>
</li>
</ul>
<h3 id="6-2-解决方案"><a href="#6-2-解决方案" class="headerlink" title="6.2 解决方案"></a>6.2 解决方案</h3><ul>
<li>  表单场景的数据协议最流行就是<a target="_blank" rel="noopener" href="https://json-schema.org/">JSON-Schema</a></li>
<li>  定义一套通用协议，简单高效的描述表单逻辑，适合开发低代码</li>
</ul>
<h3 id="6-3-JSON-Schema"><a href="#6-3-JSON-Schema" class="headerlink" title="6.3 JSON-Schema"></a>6.3 JSON-Schema</h3><ul>
<li>  <a target="_blank" rel="noopener" href="https://json-schema.org/">JSON-Schema</a>以数据描述视角驱动UI渲染，不好描述UI</li>
<li>  <a target="_blank" rel="noopener" href="https://ajv.js.org/">ajv</a>是一个JSON Schema验证器 -</li>
</ul>
<figure class="highlight pgsql"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-n18mvclacl5voy"></i><span>pgsql</span><div class="collapse show" id="collapse-n18mvclacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><code class="hljs pgsql"><span class="hljs-keyword">import</span> Ajv <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;ajv&#x27;</span>;<br>const ajv = <span class="hljs-built_in">new</span> Ajv()<br><br>const schema = &#123;<br>  <span class="hljs-keyword">type</span>: &quot;object&quot;,<br>  properties: &#123;<br>    foo: &#123; <span class="hljs-keyword">type</span>: &quot;integer&quot; &#125;,<br>    bar: &#123; <span class="hljs-keyword">type</span>: &quot;string&quot; &#125;<br>  &#125;,<br>  required: [&quot;foo&quot;],<br>  additionalProperties: <span class="hljs-keyword">false</span><br>&#125;<br><br>const <span class="hljs-keyword">validate</span> = ajv.compile(<span class="hljs-keyword">schema</span>)<br><br>const data = &#123;<br>  foo: <span class="hljs-number">1</span>,<br>  bar: &quot;abc&quot;,<br>  age: <span class="hljs-number">1</span><br>&#125;<br><br>const <span class="hljs-keyword">valid</span> = <span class="hljs-keyword">validate</span>(data)<br><span class="hljs-keyword">if</span> (!<span class="hljs-keyword">valid</span>)<br>  console.log(<span class="hljs-keyword">validate</span>.errors)<br><br></code></pre></td></tr></table></div></figure>

<h3 id="6-4-扩展的JSON-Schema"><a href="#6-4-扩展的JSON-Schema" class="headerlink" title="6.4 扩展的JSON-Schema"></a>6.4 扩展的JSON-Schema</h3><ul>
<li>  <code>Formily</code>扩展了<code>JSON-Schema</code> 属性，统一以<code>x-*</code>格式来表达扩展属性以描述数据无关的布局容器和控件，实现UI协议与数据协议混合在一起</li>
<li>  JSON Schema 引入 <code>void</code>，代表一个虚数据节点，表示该节点并不占用实际数据结构</li>
<li>  DSL(领域特定语言)(Domain Specific Language)是针对某一领域，具有受限表达性的一种计算机程序设计语言</li>
</ul>
<figure class="highlight awk"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-rid7pblacl5voy"></i><span>awk</span><div class="collapse show" id="collapse-rid7pblacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs awk">&#123;<br>  <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;string&quot;</span>,<br>  <span class="hljs-string">&quot;title&quot;</span>: <span class="hljs-string">&quot;字符串&quot;</span>,<br>  <span class="hljs-string">&quot;description&quot;</span>: <span class="hljs-string">&quot;这是一个字符串&quot;</span>,<br>  <span class="hljs-string">&quot;x-component&quot;</span>: <span class="hljs-string">&quot;Input&quot;</span>,<span class="hljs-regexp">//</span>字段 UI 组件属性<br>  <span class="hljs-string">&quot;x-component-props&quot;</span>: &#123;<span class="hljs-regexp">//</span>字段 UI 组件属性<br>    <span class="hljs-string">&quot;placeholder&quot;</span>: <span class="hljs-string">&quot;请输入&quot;</span><br>  &#125;<br>&#125;<br><br></code></pre></td></tr></table></div></figure>
<figure class="highlight awk"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-znnk2slacl5voy"></i><span>awk</span><div class="collapse show" id="collapse-znnk2slacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs awk">&#123;<br>  <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;void&quot;</span>,<br>  <span class="hljs-string">&quot;title&quot;</span>: <span class="hljs-string">&quot;卡片&quot;</span>,<br>  <span class="hljs-string">&quot;description&quot;</span>: <span class="hljs-string">&quot;这是一个卡片&quot;</span>,<br>  <span class="hljs-string">&quot;x-component&quot;</span>: <span class="hljs-string">&quot;Card&quot;</span>,<span class="hljs-regexp">//</span>字段 UI 组件属性<br>  <span class="hljs-string">&quot;properties&quot;</span>: &#123;<br>    <span class="hljs-string">&quot;name&quot;</span>: &#123;<br>      <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;string&quot;</span>,<br>      <span class="hljs-string">&quot;title&quot;</span>: <span class="hljs-string">&quot;字符串&quot;</span>,<br>      <span class="hljs-string">&quot;description&quot;</span>: <span class="hljs-string">&quot;这是一个字符串&quot;</span>,<br>      <span class="hljs-string">&quot;x-component&quot;</span>: <span class="hljs-string">&quot;Input&quot;</span>,<span class="hljs-regexp">//</span>字段 UI 组件属性<br>      <span class="hljs-string">&quot;x-component-props&quot;</span>: &#123;<span class="hljs-regexp">//</span>字段 UI 组件属性<br>        <span class="hljs-string">&quot;placeholder&quot;</span>: <span class="hljs-string">&quot;请输入&quot;</span><br>      &#125;<br>    &#125;<br>  &#125;<br>&#125;<br><br></code></pre></td></tr></table></div></figure>

<h3 id="6-5-API"><a href="#6-5-API" class="headerlink" title="6.5 API"></a>6.5 API</h3><ul>
<li><a target="_blank" rel="noopener" href="https://core.formilyjs.org/zh-CN/api/entry/create-form">createForm</a>创建一个 Form 实例，作为 ViewModel 给 UI 框架层消费<ul>
<li>  effects 副作用逻辑，用于实现各种联动逻辑</li>
<li>  <a target="_blank" rel="noopener" href="https://core.formilyjs.org/zh-CN/api/entry/field-effect-hooks#onfieldmount">onFieldMount</a>用于监听某个字段已挂载的副作用钩子</li>
<li>  <a target="_blank" rel="noopener" href="https://core.formilyjs.org/zh-CN/api/entry/field-effect-hooks#onfieldvaluechange">onFieldValueChange</a>用于监听某个字段值变化的副作用钩子</li>
<li>  <a target="_blank" rel="noopener" href="https://core.formilyjs.org/zh-CN/api/models/form#setfieldstate">setFieldState</a>可以设置字段状态</li>
</ul>
</li>
<li>  <a target="_blank" rel="noopener" href="https://core.formilyjs.org/zh-CN/api/models/field">core/Field</a>组件是用来承接普通字段的组件</li>
<li><a target="_blank" rel="noopener" href="https://react.formilyjs.org/zh-CN/api/components/field">react/Field</a>作为<code>@formily/core</code> 的 <code>createField</code> React 实现，它是专门用于将 <code>ViewModel</code> 与输入控件做绑定的桥接组件<ul>
<li>  <a target="_blank" rel="noopener" href="https://core.formilyjs.org/zh-CN/api/models/field#%E5%B1%9E%E6%80%A7">title</a>字段标题</li>
<li>  <a target="_blank" rel="noopener" href="https://core.formilyjs.org/zh-CN/api/models/field#%E5%B1%9E%E6%80%A7">required</a>字段是否必填,如果 <code>decorator</code> 指定为 <code>FormItem</code>，那么会自动出现星号提示</li>
<li>  <a target="_blank" rel="noopener" href="https://core.formilyjs.org/zh-CN/api/models/field#%E5%B1%9E%E6%80%A7">component</a>字段组件,注意 component 属性传递的是数组形式，第一个参数代表指定组件类型，第二个参数代表指定组件属性</li>
<li>  <a target="_blank" rel="noopener" href="https://core.formilyjs.org/zh-CN/api/models/field#%E5%B1%9E%E6%80%A7">decorator</a>字段装饰器,通常我们都会指定为 FormItem,注意 decorator 属性传递的是数组形式，第一个参数代表指定组件类型，第二个参数代表指定组件属性</li>
</ul>
</li>
<li>  <code>SchemaField</code>组件是专门用于解析<code>JSON-Schema</code>动态渲染表单的组件。 在使用<code>SchemaField</code>组件的时候，需要通过 <a target="_blank" rel="noopener" href="https://react.formilyjs.org/zh-CN/api/components/schema-field">createSchemaField</a> 工厂函数创建一个 <code>SchemaField`</code> 组件</li>
<li><a target="_blank" rel="noopener" href="https://react.formilyjs.org/zh-CN/api/shared/schema">Schema</a>是<code>@formily/react</code>协议驱动最核心的部分<ul>
<li>  解析 <code>json-schema</code> 的能力</li>
<li>  将 <code>json-schema</code> 转换成 <code>Field Model</code> 的能力</li>
<li>  编译 <code>json-schema</code> 表达式的能力</li>
<li>  <code>x-component</code> 的组件标识与<code>createSchemaField</code>传入的组件集合的 <code>Key</code> 匹配</li>
<li>  <code>x-decorator</code> 的组件标识与<code>createSchemaField</code>传入的组件集合的 <code>Key</code> 匹配</li>
<li>  <code>Schema</code> 的每个属性都能使用字符串表达式<code>&#123;&#123;expression&#125;&#125;</code>，表达式变量可以从 <code>createSchemaField</code> 中传入，也可以从 <code>SchemaField</code> 组件中传入</li>
</ul>
</li>
<li><a target="_blank" rel="noopener" href="https://react.formilyjs.org/zh-CN/api/shared/schema">Schema</a>属性<ul>
<li>  <a target="_blank" rel="noopener" href="https://react.formilyjs.org/zh-CN/api/shared/schema">type</a>类型</li>
<li>  <a target="_blank" rel="noopener" href="https://react.formilyjs.org/zh-CN/api/shared/schema">properties</a>属性描述</li>
<li>  <a target="_blank" rel="noopener" href="https://react.formilyjs.org/zh-CN/api/shared/schema">title</a>标题</li>
<li>  <a target="_blank" rel="noopener" href="https://react.formilyjs.org/zh-CN/api/shared/schema">required</a>必填</li>
<li>  <a target="_blank" rel="noopener" href="https://react.formilyjs.org/zh-CN/api/shared/schema">x-decorator</a>字段 UI 包装器组件</li>
<li>  <a target="_blank" rel="noopener" href="https://react.formilyjs.org/zh-CN/api/shared/schema">x-component</a>字段 UI 组件属性</li>
<li>  <a target="_blank" rel="noopener" href="https://react.formilyjs.org/zh-CN/api/shared/schema">x-component-props</a>字段 UI 组件属性</li>
<li>  <a target="_blank" rel="noopener" href="https://react.formilyjs.org/zh-CN/api/shared/schema#schemareactions">x-reactions</a>字段联动协议</li>
<li>  <a target="_blank" rel="noopener" href="https://react.formilyjs.org/zh-CN/api/shared/schema#deps">$deps</a>只能在<code>x-reactions</code>中的表达式消费，与 <code>x-reactions`</code> 定义的 <code>dependencies`</code> 对应，数组顺序一致</li>
<li>  <a target="_blank" rel="noopener" href="https://react.formilyjs.org/zh-CN/api/shared/schema#self">$self</a>代表当前字段实例，可以在普通属性表达式中使用，也能在 x-reactions 中使用</li>
</ul>
</li>
</ul>
<h3 id="6-5-表单渲染"><a href="#6-5-表单渲染" class="headerlink" title="6.5 表单渲染"></a>6.5 表单渲染</h3><ul>
<li>Formily 的表单校验使用了极其强大且灵活的<a target="_blank" rel="noopener" href="https://core.formilyjs.org/zh-CN/api/models/field#fieldvalidator">FieldValidator</a>校验引擎，校验主要分两种场景：<ul>
<li>  纯 <code>JSX</code> 场景校验属性，使用 <code>validator</code> 属性实现校验</li>
<li>  <code>Markup(JSON) Schema</code>场景协议校验属性校验，使用 <code>JSON Schema</code> 本身的校验属性与 <code>x-validator</code> 属性实现校验</li>
</ul>
</li>
</ul>
<h4 id="6-5-1-JSX-案例"><a href="#6-5-1-JSX-案例" class="headerlink" title="6.5.1 JSX 案例"></a>6.5.1 JSX 案例</h4><p>src\App.tsx</p>
<figure class="highlight javascript"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-czi31dlacl5voy"></i><span>javascript</span><div class="collapse show" id="collapse-czi31dlacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-keyword">import</span> &#123; createForm &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@formily/core&#x27;</span><br><span class="hljs-keyword">import</span> &#123; <span class="hljs-title class_">Field</span> &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@formily/react&#x27;</span><br><span class="hljs-keyword">import</span> <span class="hljs-string">&#x27;antd/dist/antd.css&#x27;</span><br><span class="hljs-keyword">import</span> &#123; <span class="hljs-title class_">Form</span>, <span class="hljs-title class_">FormItem</span>, <span class="hljs-title class_">Input</span>, <span class="hljs-title class_">NumberPicker</span> &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@formily/antd&#x27;</span><br><span class="hljs-comment">//createForm创建一个 Form 实例，作为 ViewModel 给 UI 框架层消费</span><br><span class="hljs-keyword">const</span> form = <span class="hljs-title function_">createForm</span>()<br><span class="hljs-keyword">function</span> <span class="hljs-title function_">App</span>(<span class="hljs-params"></span>) &#123;<br>  <span class="hljs-keyword">return</span> (<br>    <span class="language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">Form</span> <span class="hljs-attr">form</span>=<span class="hljs-string">&#123;form&#125;</span> <span class="hljs-attr">labelCol</span>=<span class="hljs-string">&#123;6&#125;</span> <span class="hljs-attr">wrapperCol</span>=<span class="hljs-string">&#123;10&#125;</span>&gt;</span></span><br><span class="language-xml">      <span class="hljs-tag">&lt;<span class="hljs-name">Field</span></span></span><br><span class="hljs-tag"><span class="language-xml">        <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;name&quot;</span></span></span><br><span class="hljs-tag"><span class="language-xml">        <span class="hljs-attr">title</span>=<span class="hljs-string">&quot;姓名&quot;</span></span></span><br><span class="hljs-tag"><span class="language-xml">        <span class="hljs-attr">required</span></span></span><br><span class="hljs-tag"><span class="language-xml">        <span class="hljs-attr">component</span>=<span class="hljs-string">&#123;[Input]&#125;</span></span></span><br><span class="hljs-tag"><span class="language-xml">        <span class="hljs-attr">decorator</span>=<span class="hljs-string">&#123;[FormItem]&#125;</span></span></span><br><span class="hljs-tag"><span class="language-xml">      /&gt;</span></span><br><span class="language-xml">      <span class="hljs-tag">&lt;<span class="hljs-name">Field</span></span></span><br><span class="hljs-tag"><span class="language-xml">        <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;age&quot;</span></span></span><br><span class="hljs-tag"><span class="language-xml">        <span class="hljs-attr">title</span>=<span class="hljs-string">&quot;年龄&quot;</span></span></span><br><span class="hljs-tag"><span class="language-xml">        <span class="hljs-attr">validator</span>=<span class="hljs-string">&#123;&#123;</span> <span class="hljs-attr">maximum:</span> <span class="hljs-attr">5</span> &#125;&#125;</span></span><br><span class="hljs-tag"><span class="language-xml">        <span class="hljs-attr">component</span>=<span class="hljs-string">&#123;[NumberPicker]&#125;</span></span></span><br><span class="hljs-tag"><span class="language-xml">        <span class="hljs-attr">decorator</span>=<span class="hljs-string">&#123;[FormItem]&#125;</span></span></span><br><span class="hljs-tag"><span class="language-xml">      /&gt;</span></span><br><span class="language-xml">    <span class="hljs-tag">&lt;/<span class="hljs-name">Form</span>&gt;</span></span><br>  )<br>&#125;<br><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-title class_">App</span>;<br><br></code></pre></td></tr></table></div></figure>

<h4 id="6-5-2-JSON-Schema案例"><a href="#6-5-2-JSON-Schema案例" class="headerlink" title="6.5.2 JSON Schema案例"></a>6.5.2 JSON Schema案例</h4><ul>
<li><a target="_blank" rel="noopener" href="https://react.formilyjs.org/zh-CN/api/shared/schema">schema</a>是<code>@formily/react</code>协议驱动最核心的部分<ul>
<li>  解析 <code>json-schema</code> 的能力</li>
<li>  将 <code>json-schema</code> 转换成 <code>Field Model</code> 的能力</li>
<li>  编译 <code>json-schema</code> 表达式的能力</li>
</ul>
</li>
</ul>
<p>src\App.tsx</p>
<figure class="highlight javascript"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-u33bh6lacl5voy"></i><span>javascript</span><div class="collapse show" id="collapse-u33bh6lacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-keyword">import</span> &#123; createForm &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@formily/core&#x27;</span><br><span class="hljs-keyword">import</span> &#123; createSchemaField &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@formily/react&#x27;</span><br><span class="hljs-keyword">import</span> <span class="hljs-string">&#x27;antd/dist/antd.css&#x27;</span><br><span class="hljs-keyword">import</span> &#123; <span class="hljs-title class_">Form</span>, <span class="hljs-title class_">FormItem</span>, <span class="hljs-title class_">Input</span> &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@formily/antd&#x27;</span><br><span class="hljs-keyword">const</span> form = <span class="hljs-title function_">createForm</span>()<br><span class="hljs-keyword">const</span> <span class="hljs-title class_">SchemaField</span> = <span class="hljs-title function_">createSchemaField</span>(&#123;<br>  <span class="hljs-attr">components</span>: &#123;<br>    <span class="hljs-title class_">FormItem</span>,<br>    <span class="hljs-title class_">Input</span><br>  &#125;,<br>&#125;)<br><span class="hljs-keyword">const</span> schema = &#123;<br>  <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;object&#x27;</span>,<br>  <span class="hljs-attr">properties</span>: &#123;<br>    <span class="hljs-attr">name</span>: &#123;<br>      <span class="hljs-attr">title</span>: <span class="hljs-string">`姓名`</span>,<br>      <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;string&#x27;</span>,<br>      <span class="hljs-attr">required</span>: <span class="hljs-literal">true</span>,<br>      <span class="hljs-string">&#x27;x-decorator&#x27;</span>: <span class="hljs-string">&#x27;FormItem&#x27;</span>,<span class="hljs-comment">//字段 UI 包装器组件</span><br>      <span class="hljs-string">&#x27;x-component&#x27;</span>: <span class="hljs-string">&#x27;Input&#x27;</span>,<span class="hljs-comment">//字段 UI 组件属性</span><br>    &#125;,<br>    <span class="hljs-attr">age</span>: &#123;<br>      <span class="hljs-attr">title</span>: <span class="hljs-string">`邮箱`</span>,<br>      <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;string&#x27;</span>,<br>      <span class="hljs-attr">required</span>: <span class="hljs-literal">true</span>,<br>      <span class="hljs-string">&#x27;x-validator&#x27;</span>: <span class="hljs-string">&#x27;email&#x27;</span>,<br>      <span class="hljs-string">&#x27;x-decorator&#x27;</span>: <span class="hljs-string">&#x27;FormItem&#x27;</span>,<span class="hljs-comment">//字段 UI 包装器组件</span><br>      <span class="hljs-string">&#x27;x-component&#x27;</span>: <span class="hljs-string">&#x27;Input&#x27;</span>,<span class="hljs-comment">//字段 UI 组件属性</span><br>    &#125;,<br>  &#125;,<br>&#125;<br><span class="hljs-keyword">function</span> <span class="hljs-title function_">App</span>(<span class="hljs-params"></span>) &#123;<br>  <span class="hljs-keyword">return</span> (<br>    <span class="language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">Form</span> <span class="hljs-attr">form</span>=<span class="hljs-string">&#123;form&#125;</span> <span class="hljs-attr">labelCol</span>=<span class="hljs-string">&#123;6&#125;</span> <span class="hljs-attr">wrapperCol</span>=<span class="hljs-string">&#123;10&#125;</span>&gt;</span></span><br><span class="language-xml">      <span class="hljs-tag">&lt;<span class="hljs-name">SchemaField</span> <span class="hljs-attr">schema</span>=<span class="hljs-string">&#123;schema&#125;</span> /&gt;</span></span><br><span class="language-xml">    <span class="hljs-tag">&lt;/<span class="hljs-name">Form</span>&gt;</span></span><br>  )<br>&#125;<br><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-title class_">App</span>;<br><br></code></pre></td></tr></table></div></figure>

<h4 id="6-5-3-Markup-Schema-案例"><a href="#6-5-3-Markup-Schema-案例" class="headerlink" title="6.5.3 Markup Schema 案例"></a>6.5.3 Markup Schema 案例</h4><p>src\App.tsx</p>
<figure class="highlight javascript"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-phnk0blacl5voy"></i><span>javascript</span><div class="collapse show" id="collapse-phnk0blacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-keyword">import</span> &#123; createForm &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@formily/core&#x27;</span><br><span class="hljs-keyword">import</span> &#123; createSchemaField &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@formily/react&#x27;</span><br><span class="hljs-keyword">import</span> <span class="hljs-string">&#x27;antd/dist/antd.css&#x27;</span><br><span class="hljs-keyword">import</span> &#123; <span class="hljs-title class_">Form</span>, <span class="hljs-title class_">FormItem</span>, <span class="hljs-title class_">Input</span>, <span class="hljs-title class_">NumberPicker</span> &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@formily/antd&#x27;</span><br><span class="hljs-keyword">const</span> form = <span class="hljs-title function_">createForm</span>()<br><span class="hljs-keyword">const</span> <span class="hljs-title class_">SchemaField</span> = <span class="hljs-title function_">createSchemaField</span>(&#123;<br>  <span class="hljs-attr">components</span>: &#123;<br>    <span class="hljs-title class_">Input</span>,<br>    <span class="hljs-title class_">FormItem</span>,<br>    <span class="hljs-title class_">NumberPicker</span><br>  &#125;,<br>&#125;)<br><br><span class="hljs-keyword">function</span> <span class="hljs-title function_">App</span>(<span class="hljs-params"></span>) &#123;<br>  <span class="hljs-keyword">return</span> (<br>    <span class="language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">Form</span> <span class="hljs-attr">form</span>=<span class="hljs-string">&#123;form&#125;</span> <span class="hljs-attr">labelCol</span>=<span class="hljs-string">&#123;6&#125;</span> <span class="hljs-attr">wrapperCol</span>=<span class="hljs-string">&#123;10&#125;</span>&gt;</span></span><br><span class="language-xml">      <span class="hljs-tag">&lt;<span class="hljs-name">SchemaField</span>&gt;</span></span><br><span class="language-xml">        <span class="hljs-tag">&lt;<span class="hljs-name">SchemaField.String</span></span></span><br><span class="hljs-tag"><span class="language-xml">          <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;name&quot;</span></span></span><br><span class="hljs-tag"><span class="language-xml">          <span class="hljs-attr">title</span>=<span class="hljs-string">&quot;姓名&quot;</span></span></span><br><span class="hljs-tag"><span class="language-xml">          <span class="hljs-attr">required</span></span></span><br><span class="hljs-tag"><span class="language-xml">          <span class="hljs-attr">x-component</span>=<span class="hljs-string">&quot;Input&quot;</span>//<span class="hljs-attr">字段</span> <span class="hljs-attr">UI</span> <span class="hljs-attr">组件属性</span></span></span><br><span class="hljs-tag"><span class="language-xml">          <span class="hljs-attr">x-decorator</span>=<span class="hljs-string">&quot;FormItem&quot;</span>//<span class="hljs-attr">字段</span> <span class="hljs-attr">UI</span> <span class="hljs-attr">包装器组件</span></span></span><br><span class="hljs-tag"><span class="language-xml">        /&gt;</span></span><br><span class="language-xml">        <span class="hljs-tag">&lt;<span class="hljs-name">SchemaField.Number</span></span></span><br><span class="hljs-tag"><span class="language-xml">          <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;age&quot;</span></span></span><br><span class="hljs-tag"><span class="language-xml">          <span class="hljs-attr">title</span>=<span class="hljs-string">&quot;年龄&quot;</span></span></span><br><span class="hljs-tag"><span class="language-xml">          <span class="hljs-attr">maximum</span>=<span class="hljs-string">&#123;120&#125;</span></span></span><br><span class="hljs-tag"><span class="language-xml">          <span class="hljs-attr">x-component</span>=<span class="hljs-string">&quot;NumberPicker&quot;</span>//<span class="hljs-attr">字段</span> <span class="hljs-attr">UI</span> <span class="hljs-attr">组件属性</span></span></span><br><span class="hljs-tag"><span class="language-xml">          <span class="hljs-attr">x-decorator</span>=<span class="hljs-string">&quot;FormItem&quot;</span>//<span class="hljs-attr">字段</span> <span class="hljs-attr">UI</span> <span class="hljs-attr">包装器组件</span></span></span><br><span class="hljs-tag"><span class="language-xml">        /&gt;</span></span><br><span class="language-xml">      <span class="hljs-tag">&lt;/<span class="hljs-name">SchemaField</span>&gt;</span></span><br><span class="language-xml">    <span class="hljs-tag">&lt;/<span class="hljs-name">Form</span>&gt;</span></span><br>  )<br>&#125;<br><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-title class_">App</span>;<br><br></code></pre></td></tr></table></div></figure>

<h3 id="6-6-联动校验"><a href="#6-6-联动校验" class="headerlink" title="6.6 联动校验"></a>6.6 联动校验</h3><ul>
<li>  同时我们还能在 <code>effects</code> 或者 <code>x-reactions</code> 中实现联动校验</li>
</ul>
<h4 id="6-6-1-主动联动"><a href="#6-6-1-主动联动" class="headerlink" title="6.6.1 主动联动"></a>6.6.1 主动联动</h4><ul>
<li>  <a target="_blank" rel="noopener" href="https://react.formilyjs.org/zh-CN/api/shared/schema#schemareactions">Schema 联动协议</a>，如果<code>reaction</code>对象里包含<code>target</code>，则代表<code>主动</code>联动模式，否则代表<code>被动</code>联动模式</li>
</ul>
<p>src\App.tsx</p>
<figure class="highlight javascript"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-nh18yslacl5voy"></i><span>javascript</span><div class="collapse show" id="collapse-nh18yslacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-keyword">import</span> &#123; createForm &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@formily/core&#x27;</span><br><span class="hljs-keyword">import</span> &#123; createSchemaField &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@formily/react&#x27;</span><br><span class="hljs-keyword">import</span> <span class="hljs-string">&#x27;antd/dist/antd.css&#x27;</span><br><span class="hljs-keyword">import</span> &#123; <span class="hljs-title class_">Form</span>, <span class="hljs-title class_">FormItem</span>, <span class="hljs-title class_">Input</span> &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@formily/antd&#x27;</span><br><span class="hljs-keyword">const</span> form = <span class="hljs-title function_">createForm</span>()<br><span class="hljs-keyword">const</span> <span class="hljs-title class_">SchemaField</span> = <span class="hljs-title function_">createSchemaField</span>(&#123;<br>  <span class="hljs-attr">components</span>: &#123;<br>    <span class="hljs-title class_">FormItem</span>,<br>    <span class="hljs-title class_">Input</span><br>  &#125;,<br>&#125;)<br><span class="hljs-keyword">const</span> schema = &#123;<br>  <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;object&#x27;</span>,<br>  <span class="hljs-attr">properties</span>: &#123;<br>    <span class="hljs-attr">source</span>: &#123;<br>      <span class="hljs-attr">title</span>: <span class="hljs-string">`来源`</span>,<br>      <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;string&#x27;</span>,<br>      <span class="hljs-attr">required</span>: <span class="hljs-literal">true</span>,<br>      <span class="hljs-string">&#x27;x-decorator&#x27;</span>: <span class="hljs-string">&#x27;FormItem&#x27;</span>,<span class="hljs-comment">//字段 UI 包装器组件</span><br>      <span class="hljs-string">&#x27;x-component&#x27;</span>: <span class="hljs-string">&#x27;Input&#x27;</span>,<span class="hljs-comment">//字段 UI 组件属性</span><br>      <span class="hljs-string">&quot;x-component-props&quot;</span>: &#123;<span class="hljs-comment">//字段 UI 组件属性</span><br>        <span class="hljs-string">&quot;placeholder&quot;</span>: <span class="hljs-string">&quot;请输入&quot;</span><br>      &#125;,<br>      <span class="hljs-string">&quot;x-reactions&quot;</span>: [<span class="hljs-comment">//字段联动协议</span><br>        &#123;<br>          <span class="hljs-string">&quot;target&quot;</span>: <span class="hljs-string">&quot;target&quot;</span>,<span class="hljs-comment">///要操作的字段路径，支持FormPathPattern路径语法</span><br>          <span class="hljs-comment">//代表当前字段实例，可以在普通属性表达式中使用，也能在 x-reactions 中使用</span><br>          <span class="hljs-string">&quot;when&quot;</span>: <span class="hljs-string">&quot;&#123;&#123;$self.value == &#x27;123&#x27;&#125;&#125;&quot;</span>,<span class="hljs-comment">//联动条件</span><br>          <span class="hljs-string">&quot;fulfill&quot;</span>: &#123; <span class="hljs-comment">//满足条件</span><br>            <span class="hljs-string">&quot;state&quot;</span>: &#123;<span class="hljs-comment">//更新状态</span><br>              <span class="hljs-string">&quot;visible&quot;</span>: <span class="hljs-literal">true</span><br>            &#125;<br>          &#125;,<br>          <span class="hljs-string">&quot;otherwise&quot;</span>: &#123; <span class="hljs-comment">//不满足条件</span><br>            <span class="hljs-string">&quot;state&quot;</span>: &#123;<span class="hljs-comment">//更新状态</span><br>              <span class="hljs-string">&quot;visible&quot;</span>: <span class="hljs-literal">false</span><br>            &#125;<br>          &#125;<br>        &#125;<br>      ]<br>    &#125;,<br>    <span class="hljs-attr">target</span>: &#123;<br>      <span class="hljs-string">&quot;title&quot;</span>: <span class="hljs-string">&quot;目标&quot;</span>,<br>      <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;string&quot;</span>,<br>      <span class="hljs-string">&quot;x-component&quot;</span>: <span class="hljs-string">&quot;Input&quot;</span>,<span class="hljs-comment">//字段 UI 组件属性</span><br>      <span class="hljs-string">&quot;x-component-props&quot;</span>: &#123;<span class="hljs-comment">//字段 UI 组件属性</span><br>        <span class="hljs-string">&quot;placeholder&quot;</span>: <span class="hljs-string">&quot;请输入&quot;</span><br>      &#125;,<br>      <span class="hljs-string">&#x27;x-decorator&#x27;</span>: <span class="hljs-string">&#x27;FormItem&#x27;</span><span class="hljs-comment">//字段 UI 包装器组件</span><br>    &#125;<br>  &#125;,<br>&#125;<br><span class="hljs-keyword">function</span> <span class="hljs-title function_">App</span>(<span class="hljs-params"></span>) &#123;<br>  <span class="hljs-keyword">return</span> (<br>    <span class="language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">Form</span> <span class="hljs-attr">form</span>=<span class="hljs-string">&#123;form&#125;</span> <span class="hljs-attr">labelCol</span>=<span class="hljs-string">&#123;6&#125;</span> <span class="hljs-attr">wrapperCol</span>=<span class="hljs-string">&#123;10&#125;</span>&gt;</span></span><br><span class="language-xml">      <span class="hljs-tag">&lt;<span class="hljs-name">SchemaField</span> <span class="hljs-attr">schema</span>=<span class="hljs-string">&#123;schema&#125;</span> /&gt;</span></span><br><span class="language-xml">    <span class="hljs-tag">&lt;/<span class="hljs-name">Form</span>&gt;</span></span><br>  )<br>&#125;<br><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-title class_">App</span>;<br><br></code></pre></td></tr></table></div></figure>

<h4 id="6-6-2-被动联动"><a href="#6-6-2-被动联动" class="headerlink" title="6.6.2 被动联动"></a>6.6.2 被动联动</h4><p>src\App.tsx</p>
<figure class="highlight javascript"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-zmai5dlacl5voy"></i><span>javascript</span><div class="collapse show" id="collapse-zmai5dlacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-keyword">import</span> &#123; createForm &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@formily/core&#x27;</span><br><span class="hljs-keyword">import</span> &#123; createSchemaField &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@formily/react&#x27;</span><br><span class="hljs-keyword">import</span> <span class="hljs-string">&#x27;antd/dist/antd.css&#x27;</span><br><span class="hljs-keyword">import</span> &#123; <span class="hljs-title class_">Form</span>, <span class="hljs-title class_">FormItem</span>, <span class="hljs-title class_">Input</span> &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@formily/antd&#x27;</span><br><span class="hljs-keyword">const</span> form = <span class="hljs-title function_">createForm</span>()<br><span class="hljs-keyword">const</span> <span class="hljs-title class_">SchemaField</span> = <span class="hljs-title function_">createSchemaField</span>(&#123;<br>  <span class="hljs-attr">components</span>: &#123;<br>    <span class="hljs-title class_">FormItem</span>,<br>    <span class="hljs-title class_">Input</span><br>  &#125;,<br>&#125;)<br><span class="hljs-keyword">const</span> schema = &#123;<br>  <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;object&#x27;</span>,<br>  <span class="hljs-attr">properties</span>: &#123;<br>    <span class="hljs-attr">source</span>: &#123;<br>      <span class="hljs-attr">title</span>: <span class="hljs-string">`来源`</span>,<br>      <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;string&#x27;</span>,<br>      <span class="hljs-attr">required</span>: <span class="hljs-literal">true</span>,<br>      <span class="hljs-string">&#x27;x-decorator&#x27;</span>: <span class="hljs-string">&#x27;FormItem&#x27;</span>,<span class="hljs-comment">//字段 UI 包装器组件</span><br>      <span class="hljs-string">&#x27;x-component&#x27;</span>: <span class="hljs-string">&#x27;Input&#x27;</span>,<span class="hljs-comment">//字段 UI 组件属性</span><br>      <span class="hljs-string">&quot;x-component-props&quot;</span>: &#123;<span class="hljs-comment">//字段 UI 组件属性</span><br>        <span class="hljs-string">&quot;placeholder&quot;</span>: <span class="hljs-string">&quot;请输入&quot;</span><br>      &#125;<br>    &#125;,<br>    <span class="hljs-attr">target</span>: &#123;<br>      <span class="hljs-string">&quot;title&quot;</span>: <span class="hljs-string">&quot;目标&quot;</span>,<br>      <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;string&quot;</span>,<br>      <span class="hljs-string">&quot;x-component&quot;</span>: <span class="hljs-string">&quot;Input&quot;</span>,<span class="hljs-comment">//字段 UI 组件属性</span><br>      <span class="hljs-string">&quot;x-component-props&quot;</span>: &#123;<span class="hljs-comment">//字段 UI 组件属性</span><br>        <span class="hljs-string">&quot;placeholder&quot;</span>: <span class="hljs-string">&quot;请输入&quot;</span><br>      &#125;,<br>      <span class="hljs-string">&#x27;x-decorator&#x27;</span>: <span class="hljs-string">&#x27;FormItem&#x27;</span>,<span class="hljs-comment">//字段 UI 包装器组件</span><br>      <span class="hljs-string">&quot;x-reactions&quot;</span>: [<span class="hljs-comment">//字段联动协议</span><br>        &#123;<br>          <span class="hljs-string">&quot;dependencies&quot;</span>: [<span class="hljs-string">&quot;source&quot;</span>],<br>          <span class="hljs-comment">//只能在x-reactions中的表达式消费，与 x-reactions 定义的 dependencies 对应，数组顺序一致</span><br>          <span class="hljs-string">&quot;when&quot;</span>: <span class="hljs-string">&quot;&#123;&#123;$deps[0] == &#x27;123&#x27;&#125;&#125;&quot;</span>,<br>          <span class="hljs-string">&quot;fulfill&quot;</span>: &#123;<br>            <span class="hljs-string">&quot;state&quot;</span>: &#123;<br>              <span class="hljs-string">&quot;visible&quot;</span>: <span class="hljs-literal">true</span><br>            &#125;<br>          &#125;,<br>          <span class="hljs-string">&quot;otherwise&quot;</span>: &#123;<br>            <span class="hljs-string">&quot;state&quot;</span>: &#123;<br>              <span class="hljs-string">&quot;visible&quot;</span>: <span class="hljs-literal">false</span><br>            &#125;<br>          &#125;<br>        &#125;<br>      ]<br>    &#125;<br>  &#125;,<br>&#125;<br><span class="hljs-keyword">function</span> <span class="hljs-title function_">App</span>(<span class="hljs-params"></span>) &#123;<br>  <span class="hljs-keyword">return</span> (<br>    <span class="language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">Form</span> <span class="hljs-attr">form</span>=<span class="hljs-string">&#123;form&#125;</span> <span class="hljs-attr">labelCol</span>=<span class="hljs-string">&#123;6&#125;</span> <span class="hljs-attr">wrapperCol</span>=<span class="hljs-string">&#123;10&#125;</span>&gt;</span></span><br><span class="language-xml">      <span class="hljs-tag">&lt;<span class="hljs-name">SchemaField</span> <span class="hljs-attr">schema</span>=<span class="hljs-string">&#123;schema&#125;</span> /&gt;</span></span><br><span class="language-xml">    <span class="hljs-tag">&lt;/<span class="hljs-name">Form</span>&gt;</span></span><br>  )<br>&#125;<br><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-title class_">App</span>;<br><br></code></pre></td></tr></table></div></figure>

<h4 id="6-6-3-effects"><a href="#6-6-3-effects" class="headerlink" title="6.6.3 effects"></a>6.6.3 effects</h4><p>src\App.tsx</p>
<figure class="highlight typescript"><i class="iconfont icon-top" type="button" data-toggle="collapse" data-target="#collapse-ubggbmlacl5voy"></i><span>typescript</span><div class="collapse show" id="collapse-ubggbmlacl5voy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">import</span> &#123; createForm, onFieldMount, onFieldValueChange &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@formily/core&#x27;</span><br><span class="hljs-keyword">import</span> &#123; createSchemaField &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@formily/react&#x27;</span><br><span class="hljs-keyword">import</span> <span class="hljs-string">&#x27;antd/dist/antd.css&#x27;</span><br><span class="hljs-keyword">import</span> &#123; <span class="hljs-title class_">Form</span>, <span class="hljs-title class_">FormItem</span>, <span class="hljs-title class_">Input</span> &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@formily/antd&#x27;</span><br><span class="hljs-keyword">const</span> form = <span class="hljs-title function_">createForm</span>(&#123;<br>  <span class="hljs-title function_">effects</span>(<span class="hljs-params"></span>) &#123;<span class="hljs-comment">//effects 副作用逻辑，用于实现各种联动逻辑</span><br>    <span class="hljs-comment">//用于监听某个字段已挂载的副作用钩子</span><br>    <span class="hljs-title function_">onFieldMount</span>(<span class="hljs-string">&#x27;target&#x27;</span>, <span class="hljs-function">(<span class="hljs-params">field: <span class="hljs-built_in">any</span></span>) =&gt;</span> &#123;<br>      <span class="hljs-comment">//可以设置字段状态</span><br>      form.<span class="hljs-title function_">setFieldState</span>(field.<span class="hljs-title function_">query</span>(<span class="hljs-string">&#x27;target&#x27;</span>), <span class="hljs-function">(<span class="hljs-params">state</span>) =&gt;</span> &#123;<br>        <span class="hljs-keyword">if</span> (field.<span class="hljs-property">value</span> === <span class="hljs-string">&#x27;123&#x27;</span>) &#123;<br>          state.<span class="hljs-property">visible</span> = <span class="hljs-literal">true</span>;<br>        &#125; <span class="hljs-keyword">else</span> &#123;<br>          state.<span class="hljs-property">visible</span> = <span class="hljs-literal">false</span>;<br>        &#125;<br>      &#125;)<br>    &#125;)<br>    <span class="hljs-comment">//用于监听某个字段值变化的副作用钩子</span><br>    <span class="hljs-title function_">onFieldValueChange</span>(<span class="hljs-string">&#x27;source&#x27;</span>, <span class="hljs-function">(<span class="hljs-params">field: <span class="hljs-built_in">any</span></span>) =&gt;</span> &#123;<br>      form.<span class="hljs-title function_">setFieldState</span>(field.<span class="hljs-title function_">query</span>(<span class="hljs-string">&#x27;target&#x27;</span>), <span class="hljs-function">(<span class="hljs-params">state</span>) =&gt;</span> &#123;<br>        <span class="hljs-keyword">if</span> (field.<span class="hljs-property">value</span> === <span class="hljs-string">&#x27;123&#x27;</span>) &#123;<br>          state.<span class="hljs-property">visible</span> = <span class="hljs-literal">true</span>;<br>        &#125; <span class="hljs-keyword">else</span> &#123;<br>          state.<span class="hljs-property">visible</span> = <span class="hljs-literal">false</span>;<br>        &#125;<br>      &#125;)<br>    &#125;)<br>  &#125;,<br>&#125;)<br><span class="hljs-keyword">const</span> <span class="hljs-title class_">SchemaField</span> = <span class="hljs-title function_">createSchemaField</span>(&#123;<br>  <span class="hljs-attr">components</span>: &#123;<br>    <span class="hljs-title class_">FormItem</span>,<br>    <span class="hljs-title class_">Input</span><br>  &#125;,<br>&#125;)<br><span class="hljs-keyword">const</span> schema = &#123;<br>  <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;object&#x27;</span>,<br>  <span class="hljs-attr">properties</span>: &#123;<br>    <span class="hljs-attr">source</span>: &#123;<br>      <span class="hljs-attr">title</span>: <span class="hljs-string">`来源`</span>,<br>      <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;string&#x27;</span>,<br>      <span class="hljs-attr">required</span>: <span class="hljs-literal">true</span>,<br>      <span class="hljs-string">&#x27;x-decorator&#x27;</span>: <span class="hljs-string">&#x27;FormItem&#x27;</span>,<span class="hljs-comment">//字段 UI 包装器组件</span><br>      <span class="hljs-string">&#x27;x-component&#x27;</span>: <span class="hljs-string">&#x27;Input&#x27;</span>,<span class="hljs-comment">//字段 UI 组件属性</span><br>      <span class="hljs-string">&quot;x-component-props&quot;</span>: &#123;<span class="hljs-comment">//字段 UI 组件属性</span><br>        <span class="hljs-string">&quot;placeholder&quot;</span>: <span class="hljs-string">&quot;请输入&quot;</span><br>      &#125;<br>    &#125;,<br>    <span class="hljs-attr">target</span>: &#123;<br>      <span class="hljs-string">&quot;title&quot;</span>: <span class="hljs-string">&quot;目标&quot;</span>,<br>      <span class="hljs-string">&quot;type&quot;</span>: <span class="hljs-string">&quot;string&quot;</span>,<br>      <span class="hljs-string">&#x27;x-decorator&#x27;</span>: <span class="hljs-string">&#x27;FormItem&#x27;</span>,<span class="hljs-comment">//字段 UI 包装器组件</span><br>      <span class="hljs-string">&quot;x-component&quot;</span>: <span class="hljs-string">&quot;Input&quot;</span>,<span class="hljs-comment">//字段 UI 组件属性</span><br>      <span class="hljs-string">&quot;x-component-props&quot;</span>: &#123;<span class="hljs-comment">//字段 UI 组件属性</span><br>        <span class="hljs-string">&quot;placeholder&quot;</span>: <span class="hljs-string">&quot;请输入&quot;</span><br>      &#125;<br>    &#125;<br>  &#125;<br>&#125;<br><span class="hljs-keyword">function</span> <span class="hljs-title function_">App</span>(<span class="hljs-params"></span>) &#123;<br>  <span class="hljs-keyword">return</span> (<br>    <span class="language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">Form</span> <span class="hljs-attr">form</span>=<span class="hljs-string">&#123;form&#125;</span> <span class="hljs-attr">labelCol</span>=<span class="hljs-string">&#123;6&#125;</span> <span class="hljs-attr">wrapperCol</span>=<span class="hljs-string">&#123;10&#125;</span>&gt;</span></span><br><span class="language-xml">      <span class="hljs-tag">&lt;<span class="hljs-name">SchemaField</span> <span class="hljs-attr">schema</span>=<span class="hljs-string">&#123;schema&#125;</span> /&gt;</span></span><br><span class="language-xml">    <span class="hljs-tag">&lt;/<span class="hljs-name">Form</span>&gt;</span></span><br>  )<br>&#125;<br><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-title class_">App</span>;<br><br></code></pre></td></tr></table></div></figure>
                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E7%BB%84%E4%BB%B6%E5%BA%93/" class="category-chain-item">组件库</a>
  
  
    <span>></span>
    
  <a href="/categories/%E7%BB%84%E4%BB%B6%E5%BA%93/formily/" class="category-chain-item">formily</a>
  
  

  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/%E7%BB%84%E4%BB%B6%E5%BA%93/">#组件库</a>
      
        <a href="/tags/formily/">#formily</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>formily基础</div>
      <div>http://81.68.132.127/2022/11/11/formily/formily基础/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Ikki</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年11月11日</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>更新于</div>
          <div>2022年11月11日</div>
        </div>
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/11/11/formily/umi4+formily/" title="umi4+formily">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">umi4+formily</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/10/31/react/router/%E5%AE%9E%E7%8E%B0%E7%AE%80%E7%89%88router/" title="实现一个简版mini-router">
                        <span class="hidden-mobile">实现一个简版mini-router</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  <article id="comments" lazyload>
    
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://lib.baomitu.com/valine/1.5.1/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"6KzYWc2oaEBaHgNl4UIicMJC-gzGzoHsz","appKey":"vJ4FIwKeHRmHraCJraAsjyZ7","path":"window.location.pathname","placeholder":"请输入你的评论\n昵称为必填项目(输入QQ号码可以自动获取昵称和邮箱)\n虽然email不是必选，但是填写了email可以收到推送通知哦！","avatar":"retro","meta":["nick","mail","link"],"requiredFields":[],"pageSize":10,"lang":"zh-CN","highlight":true,"recordIP":true,"serverURLs":"","emojiCDN":null,"emojiMaps":null,"enableQQ":true},
          {
            el: "#valine",
            path: window.location.pathname
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          var imgSelector = '#valine .vcontent img:not(.vemoji)';
          Fluid.plugins.imageCaption(imgSelector);
          Fluid.plugins.fancyBox(imgSelector);
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


  </article>


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
      IKKI-专业BUG开发
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="busuanzi_container_site_pv" style="display: none">
        总访问量 
        <span id="busuanzi_value_site_pv"></span>
         次
      </span>
    
    
      <span id="busuanzi_container_site_uv" style="display: none">
        总访客数 
        <span id="busuanzi_value_site_uv"></span>
         人
      </span>
    
    
  
</div>

  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>




  
<script src="/fluid/js/star.js"></script>



<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
